package com.example;

import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class FlowReducer extends Reducer<Text, Access, NullWritable, Text> {
    @Override
    protected void reduce(Text key, Iterable<Access> values, Context context) throws IOException, InterruptedException {
        long upSum = 0;
        long downSum = 0;

        for (Access access : values) {
            upSum += access.getUpFlow();
            downSum += access.getDownFlow();
        }

        long sumFlow = upSum + downSum;
        context.write(NullWritable.get(), new Text(key.toString() + "\t" + upSum + "\t" + downSum + "\t" + sumFlow));
    }
}
